package org.wmq.javafxmapcollectioncs.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.lang.generator.SnowflakeGenerator;
import cn.hutool.db.Entity;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import org.wmq.javafxmapcollectioncs.God;
import org.wmq.javafxmapcollectioncs.Util.IdGenerator;
import org.wmq.javafxmapcollectioncs.model.Entity.MapEntity;

public class AddViewController {

    @FXML
    private TextField nameText;

    @FXML
    private TextField mapTypeText;

    @FXML
    private TextField mediumText;

    @FXML
    private TextField urlText;

    @FXML
    private DatePicker publicationTImePicker;

    @FXML
    private DatePicker collectionTImePicker;

    @FXML
    private TextArea introductionText;

    @FXML
    private Button addButton;

    @FXML
    private void initialize() {
        // 初始化逻辑可以放在这里
    }

    @FXML
    private void addMap() {
        // 实现添加地图的逻辑
        System.out.println("Adding a new map");
        // 获取输入的值
        String name = nameText.getText();
        String mapType = mapTypeText.getText();
        String medium = mediumText.getText();
        String url = urlText.getText();
        String introduction = introductionText.getText();
        // 获取日期选择器的值
        java.time.LocalDate publicationTime = publicationTImePicker.getValue();
        java.time.LocalDate collectionTime = collectionTImePicker.getValue();

        // 这里可以添加将这些值保存到数据库或模型对象的逻辑
        MapEntity mapEntity = new MapEntity(name, url, introduction, mapType, medium, publicationTime, collectionTime);
        mapEntity.setId(IdGenerator.getId());
        God.getGod().getMapEntityList().add(mapEntity);
        God.getGod().getMapEntityList().moveToTail();
        God.getGod().getMapEntityService().add(mapEntity);
    }
}